<template>
	<view>
		<view class="zabj">
			<view @click="on_url('../../pages/banmi/user_set',1)" class="flex j-f pt2" style="padding-right: 60rpx;">
				<image style="width: 50rpx;height: 50rpx;" src="../../static/tab/shezhi.png"></image>
			</view>
			<view class=" flex a-c j-b head">
				<view class="flex a-c" @click="on_url('../../pages/banmi/user_set',1)">
					<view class="">
						<image class="q_y face" :src="user.face|getFace">
						</image>
					</view>
					<view class="ml20" style="margin-top: -10rpx;">
						<text class="w800" style="font-size: 40rpx;color: #fff;">{{user.nickname}}</text>
						<view class="cff pt1">
							<text>Uid:{{user.uid}}</text>
						</view>
					</view>
				</view>
				<view @click="on_sign()">
					<view class="flex j-c  t_c a-c bg-white banmi_button_2"
						style="height: 100rpx;border-radius: 10rpx;background-color: #6495ED;width: 180rpx;">
						<view class="">
							<view class="">
								<text class="f30 w800 cff">{{user_find.integral}}</text>
							</view>
							<view class="">
								<text class="f26 cff" v-if="is_sign!='0'">已签到</text>
								<text class="f26 cff" v-else>签到+{{set_find.sing_num}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>

		</view>
		<view class="p2">
			<view class="p20 b_y" style="margin-top: -200rpx;background-color: #fff;">
				<view @click="on_url('../../pages/banmichaoqiangbizhi/my_shop_collection',1)" class="p20    "
					style="background-color: #fff;padding-top: 40rpx;padding-bottom: 40rpx;">
					<view class="flex j-b a-c">
						<view class="flex a-c">
							<icon-collection-files size="40" color="#333"></icon-collection-files>
							<text class="ml1">我的收藏</text>
						</view>
						<view class="">
							<image style="width: 30rpx;height: 30rpx;" src="../../static/tab/you.png"></image>
						</view>
					</view>
				</view>
				<view @click="on_url('../../pages/banmichaoqiangbizhi/shop_add',1)" class="p20"
					style="padding-top: 20rpx;padding-bottom: 40rpx;">
					<view class="flex j-b a-c">
						<view class="flex a-c">
							<icon-add-mode size="40" color="#333"></icon-add-mode>
							<text class="ml1">我要投稿</text>
						</view>
						<view class="">
							<image style="width: 30rpx;height: 30rpx;" src="../../static/tab/you.png"></image>
						</view>
					</view>
				</view>
				<view @click="on_url('../../pages/banmichaoqiangbizhi/my_shop',1)" class="p20"
					style="padding-top: 20rpx;padding-bottom: 40rpx;">
					<view class="flex j-b a-c">
						<view class="flex a-c">
							<icon-graphic-design size="40" color="#333"></icon-graphic-design>
							<text class="ml1">我的投稿</text>
						</view>
						<view class="">
							<image style="width: 30rpx;height: 30rpx;" src="../../static/tab/you.png"></image>
						</view>
					</view>
				</view>
				<view @click="on_url('../../pages/banmichaoqiangbizhi/my_download',1)" class="p20"
					style="padding-top: 20rpx;padding-bottom: 40rpx;">
					<view class="flex j-b a-c">
						<view class="flex a-c">
							<icon-download-four size="40" color="#333"></icon-download-four>
							<text class="ml1">我的下载</text>
						</view>
						<view class="">
							<image style="width: 30rpx;height: 30rpx;" src="../../static/tab/you.png"></image>
						</view>
					</view>
				</view>

			</view>
		</view>
		<tabbar class="">

		</tabbar>

	</view>
</template>

<script>
	let interstitialAd = null;
	let videoAd = null

	export default {
		components: {

		},
		data() {
			return {
				user: {
					face: '',
					uid: 888888,
					nickname: '！请登录'
				},
				token: '',
				is_sign: 0,
				user_find: {},
				set_find: {},
				json: {
					download_num: 5,
					sing_num: 5,
					status: 1
				}
			}
		},
		onLoad() {

			var that = this;
			this.token = uni.getStorageSync('token');
			this.api_path = 'banmichaoqiangbizhi';
			this.set_find = this.get_plugin_set

			// #ifdef MP-WEIXIN
			this.advideo(this.set_find.mp_wx_video_ad);
			// #endif
			// #ifdef  MP-TOUTIAO
			this.video_init_dou(this.set_find.mp_dou_video_ad);
			// #endif


			if (this.token) {
				this.init();
				this.is_my_sign();
				//监听头像修改
				uni.$on('banmi_face', function(data) {
					that.user.face = data.face
				})
				//监听昵称修改
				uni.$on('banmi_nickname', function(data) {
					that.user.nickname = data.nickname
				})
			}
			uni.$on('banmi_login', function(data) {
				that.token = uni.getStorageSync('token');
				that.init();
				that.is_my_sign();
			})




			this.singlog_ = false;

		},
		methods: {

			// qq_video_ad() {
			// 	let videoAd = qq.createRewardedVideoAd({
			// 		adUnitId: "f0f86362xxxxxxxxx473"
			// 	})
			// 	//发生错误的回调
			// 	videoAd.onError(function(res) {
			// 		console.log('videoAd onError', res)
			// 	})
			// 	//加载的回调
			// 	videoAd.onLoad(function(res) {
			// 		console.log('videoAd onLoad', res)
			// 	})
			// 	//视频被关掉的回调，这里注意，回调有个参数res.isEnded是判断用户中途关闭广告的！
			// 	videoAd.onClose(function(res) {
			// 		console.log('videoAd onClose', res)
			// 		if (res.isEnded) {
			// 			console.log('观看完成')
			// 			let params = {
			// 				content,
			// 				email,
			// 				name,
			// 				number,
			// 				title,
			// 				yzm
			// 			}
			// 			_this.props.asyncSub(_this.props.message.cookieData.cookie, params)
			// 		} else {
			// 			console.log('半途而废')
			// 			Taro.showModal({
			// 				title: "未观看完成",
			// 				content: "请支持开发者维护这个应用，看完后，会自动提交！"
			// 			})
			// 		}
			// 	})
			// 	//这里才是打开广告，展示给用户！
			// 	videoAd.load().then(() => {
			// 		console.log('激励视频加载成功');
			// 		videoAd.show().then(() => {
			// 			console.log('激励视频 广告显示成功')
			// 		}).catch(err => {
			// 			console.log('激励视频 广告显示失败')
			// 		})
			// 	}).catch(err => {
			// 		console.log('激励视频加载失败');
			// 	})

			// },
			//微信 观看激励广告
			on_video_ad() {
				if (videoAd) {
					videoAd.show().catch(() => {
						// 失败重试
						videoAd.load()
							.then(() => videoAd.show())
							.catch(err => {
								console.log('激励视频 广告显示失败')
							})
					})
				}
				return
			},
			//微信 加载激励广告
			advideo(adUnitId) {
				if (!adUnitId) {
					return
				}
				var that = this;
				// 在页面onLoad回调事件中创建激励视频广告实例
				if (wx.createRewardedVideoAd) {
					videoAd = wx.createRewardedVideoAd({
						adUnitId: adUnitId
					})
					videoAd.onLoad(() => {
						console.log('视频 广告加载成功')
					})
					videoAd.onError((err) => {
						console.log('视频 广告加载失败')
					})
					videoAd.onClose((res) => {
						//广告观看成功 关闭
						if (res.isEnded == true) {
							that.on_sign_ajax();
						}
					})
				}
			},
			//抖音广告预加载 
			video_init_dou(adUnitId) {
				let that = this;
				if (!adUnitId) {
					return
				}
				this.dou_ad = tt.createRewardedVideoAd({
					adUnitId: adUnitId
				});
				// 监听错误
				this.dou_ad.onError(err => {
					tt.hideLoading();
					switch (err.errCode) {
						case 1004:
							// 无合适的广告
							break;
						default:
							// 更多请参考错误码文档
					}
				});
				// 监听视频播放完成
				this.dou_ad.onClose(data => {
					tt.hideLoading();
					if (data.isEnded) {
						that.on_sign_ajax();
					} else {
						console.log('未观看完视频');
					}
				});

				// 预加载资源
				this.dou_ad.load();
			},

			// 展示抖音激励视频
			show_dou_Video() {
				tt.showLoading();
				this.dou_ad.show();
			},
			is_my_sign() {
				let requestParams = {};
				this.Http.post('/plugin.php/banmichaoqiangbizhi/api/Sign/my_signin', requestParams).then(ret => {
					if (ret.status == 200) {
						this.is_sign = ret.data.log
						this.user_find = ret.data.user_find;
					}
				})
			},
			on_sign() {
				if (!uni.getStorageSync('token')) {
					uni.navigateTo({
						url: '/pages/banmi/user_login'
					})
					return
				}
				if (this.is_sign > 0) {
					uni.showToast({
						title: '今日已签到',
						icon: 'error'
					})
					return
				}
				// #ifdef H5
				this.on_sign_ajax();
				// #endif
				// #ifdef MP-WEIXIN
				//弹出微信视频广告
				if (this.set_find.mp_wx_video_ad) {
					this.on_video_ad();
					return
				}
				this.on_sign_ajax();
				// #endif
				// #ifdef MP-TOUTIAO
				if (this.set_find.mp_dou_video_ad) {
					this.show_dou_Video();
					return
				}
				this.on_sign_ajax();
				// #endif
			},
			on_sign_ajax() {
				if (this.singlog_) {
					return
				}
				uni.showLoading({
					title: '签到中...'
				})
				this.singlog_ = true;
				let requestParams = {};
				this.Http.post('/plugin.php/banmichaoqiangbizhi/api/Sign/signin', requestParams).then(ret => {
					uni.showToast({
						title: ret.msg,
						icon: 'none'
					})
					this.singlog_ = false;
					if (ret.status == 200) {
						this.is_my_sign();
						this.is_sign = 1
					}
				})
			},
			init() {
				this.Banmikeji.user_info().then(ret => {
					if (ret != 0) {
						this.user = ret.data.user;
						return
					} else {
						this.token = uni.getStorageSync('token');
						this.user_id = uni.getStorageSync('user_id');
					}
				})
			},
			article_view(index) {
				uni.navigateTo({
					url: '/pages/banmi/article_view?id=' + index
				})
			},
			on_url(url, index) {

				if (index == 1) {
					if (!uni.getStorageSync('token')) {
						uni.navigateTo({
							url: '/pages/banmi/user_login'
						})
						return
					}
				}
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.head {
		padding-top: 10rpx;
		padding-right: 60rpx;
		padding-left: 60rpx;
	}

	.zabj {
		background-size: 100% 100%;
		-moz-background-size: 100% 100%;
		height: 450rpx;
		background-repeat: no-repeat;
		background-color: #5013A6;
		border-bottom-left-radius: 50rpx;
		border-bottom-right-radius: 50rpx;
	}

	text {
		font-size: 30rpx;
	}
</style>